/******************************************************************************
 * Copyright (C) 2013 - 2018 ShenZhen OnePlus Technology Co.,Ltd All Rights Reserved.
 * 本软件为深圳万普拉斯科技有限公司开发研制。未经本公司正式书面同意，其他任何个人、团体不得使用、复制、修改或发布本软件.
 *****************************************************************************/
package com.data.reports.manager.database;

import org.apache.commons.lang.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author hujifang
 * @version V1.0
 * @Title: DbDriverClassUtil.java
 * @Package com.data.reports.manager.database
 * @Description
 * @date 2018 03-16 17:51.
 */
public class DbDriverClassUtil {

    private final static Map<String, String> matchDriverMap = new HashMap<>();

    static {
        matchDriverMap.put("jdbc:odps", "com.aliyun.odps.jdbc.OdpsDriver");
        matchDriverMap.put("jdbc:derby", "org.apache.derby.jdbc.EmbeddedDriver");
        matchDriverMap.put("jdbc:mysql", "com.mysql.jdbc.Driver");
        matchDriverMap.put("jdbc:oracle", "oracle.jdbc.driver.OracleDriver");
        matchDriverMap.put("jdbc:microsoft", "com.microsoft.jdbc.sqlserver.SQLServerDriver");
        matchDriverMap.put("jdbc:sybase:Tds", "com.sybase.jdbc2.jdbc.SybDriver");
        matchDriverMap.put("jdbc:jtds", "net.sourceforge.jtds.jdbc.Driver");
        matchDriverMap.put("jdbc:postgresql", "org.postgresql.Driver");
        matchDriverMap.put("jdbc:fake", "com.alibaba.druid.mock.MockDriver");
        matchDriverMap.put("jdbc:mock", "com.alibaba.druid.mock.MockDriver");
        matchDriverMap.put("jdbc:hsqldb", "org.hsqldb.jdbcDriver");
        matchDriverMap.put("jdbc:db2", "COM.ibm.db2.jdbc.app.DB2Driver");
        matchDriverMap.put("jdbc:sqlite", "org.sqlite.JDBC");
        matchDriverMap.put("jdbc:ingres", "com.ingres.jdbc.IngresDriver");
        matchDriverMap.put("jdbc:h2", "org.h2.Driver");
        matchDriverMap.put("jdbc:mckoi", "com.mckoi.JDBCDriver");
        matchDriverMap.put("jdbc:cloudscape", "COM.cloudscape.core.JDBCDriver");
        matchDriverMap.put("jdbc:informix-sqli", "com.informix.jdbc.IfxDriver");
        matchDriverMap.put("jdbc:timesten", "com.timesten.jdbc.TimesTenDriver");
        matchDriverMap.put("jdbc:as400", "com.ibm.as400.access.AS400JDBCDriver");
        matchDriverMap.put("jdbc:sapdb", "com.sap.dbtech.jdbc.DriverSapDB");
        matchDriverMap.put("jdbc:JSQLConnect", "com.jnetdirect.jsql.JSQLDriver");
        matchDriverMap.put("jdbc:JTurbo", "com.newatlanta.jturbo.driver.Driver");
        matchDriverMap.put("jdbc:firebirdsql", "org.firebirdsql.jdbc.FBDriver");
        matchDriverMap.put("jdbc:interbase", "interbase.interclient.Driver");
        matchDriverMap.put("jdbc:pointbase", "com.pointbase.jdbc.jdbcUniversalDriver");
        matchDriverMap.put("jdbc:edbc", "ca.edbc.jdbc.EdbcDriver");
        matchDriverMap.put("jdbc:mimer:multi1", "com.mimer.jdbc.Driver");
    }

    public static String getDriverClassByUrl(String url) {
        if (StringUtils.isBlank(url)) {
            return null;
        }
        for (String key : matchDriverMap.keySet()) {
            if (url.contains(key)) {
                return matchDriverMap.get(key);
            }
        }
        return null;
    }

}
